import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";
import store from "@/store";
// import Dashboard from '@/views/layout/index.vue'

// const asyncRoutes=[
//     {
//         path: '/',
//         name: "dashboard",
//         meta: { title: '后台首页' },
//         component: Dashboard,
//     }
// ]

const routes = [
  {
    path: "/",
    meta: { title: "首页" },
    name: "GallAdminIndex",
    component: () => import("../views/GallAdminIndex.vue"),
    children: [
      {
        path: "/",
        meta: { title: "首页" },
        name: "index",
        component: () => import("../views/index/index.vue"),
      },
      {
        path: "/about",
        meta: { title: "关于我们" },
        name: "about",
        component: () => import("../views/about/index.vue"),
      },
      {
        path: "/product",
        meta: { title: "产品中心" },
        name: "product",
        component: () => import("../views/product/index.vue"),
        children: [
          {
            path: "/product",
            meta: { title: "产品列表" },
            name: "productList",
            component: () => import("../views/product/list.vue"),
          },
          {
            path: "/product/details",
            meta: { title: "产品详情" },
            name: "productDetails",
            component: () => import("../views/product/details.vue"),
          },
        ],
      },
      {
        path: "/news",
        meta: { title: "新闻动态" },
        name: "news",
        component: () => import("../views/news/index.vue"),
        children: [
          {
            path: "/news",
            meta: { title: "新闻列表" },
            name: "newsList",
            component: () => import("../views/news/list.vue"),
          },
          {
            path: "/news/details",
            meta: { title: "新闻详情" },
            name: "newsDetails",
            component: () => import("../views/news/details.vue"),
          },
        ],
      },
      {
        path: "/contact",
        meta: { title: "新闻动态" },
        name: "contact",
        component: () => import("../views/contact/index.vue"),
      },
    ],
  },
  {
    path: "/admin",
    name: "Admin",
    component: () => import("../views/admin/Index.vue"),
    meta: { auth: true },
    props: true,
    children: [
      {
        path: "/admin",
        meta: { title: "后台首页" },
        name: "AdminIndex",
        component: () => import("../views/admin/index/Index.vue"),
      },
      {
        path: "list/:id",
        meta: { title: "后台首页1" },
        name: "AdminList",
        component: () => import("../views/admin/index/Index.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/login/Index.vue"),
  },
];

const router = createRouter({
  // 引入访问模式
  history: createWebHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    console.log(savedPosition);
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  },
});
export default router;
